using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace DataAccess
{
	/// <summary>
	/// Strongly-typed collection for the ASPStateTempSession class.
	/// </summary>
    [Serializable]
	public partial class ASPStateTempSessionCollection : ActiveList<ASPStateTempSession, ASPStateTempSessionCollection>
	{	   
		public ASPStateTempSessionCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>ASPStateTempSessionCollection</returns>
		public ASPStateTempSessionCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                ASPStateTempSession o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the ASPStateTempSessions table.
	/// </summary>
	[Serializable]
	public partial class ASPStateTempSession : ActiveRecord<ASPStateTempSession>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public ASPStateTempSession()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public ASPStateTempSession(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public ASPStateTempSession(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public ASPStateTempSession(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("ASPStateTempSessions", TableType.Table, DataService.GetInstance("mainConnection"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarSessionId = new TableSchema.TableColumn(schema);
				colvarSessionId.ColumnName = "SessionId";
				colvarSessionId.DataType = DbType.String;
				colvarSessionId.MaxLength = 88;
				colvarSessionId.AutoIncrement = false;
				colvarSessionId.IsNullable = false;
				colvarSessionId.IsPrimaryKey = true;
				colvarSessionId.IsForeignKey = false;
				colvarSessionId.IsReadOnly = false;
				colvarSessionId.DefaultSetting = @"";
				colvarSessionId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSessionId);
				
				TableSchema.TableColumn colvarCreated = new TableSchema.TableColumn(schema);
				colvarCreated.ColumnName = "Created";
				colvarCreated.DataType = DbType.DateTime;
				colvarCreated.MaxLength = 0;
				colvarCreated.AutoIncrement = false;
				colvarCreated.IsNullable = false;
				colvarCreated.IsPrimaryKey = false;
				colvarCreated.IsForeignKey = false;
				colvarCreated.IsReadOnly = false;
				
						colvarCreated.DefaultSetting = @"(getutcdate())";
				colvarCreated.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreated);
				
				TableSchema.TableColumn colvarExpires = new TableSchema.TableColumn(schema);
				colvarExpires.ColumnName = "Expires";
				colvarExpires.DataType = DbType.DateTime;
				colvarExpires.MaxLength = 0;
				colvarExpires.AutoIncrement = false;
				colvarExpires.IsNullable = false;
				colvarExpires.IsPrimaryKey = false;
				colvarExpires.IsForeignKey = false;
				colvarExpires.IsReadOnly = false;
				colvarExpires.DefaultSetting = @"";
				colvarExpires.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExpires);
				
				TableSchema.TableColumn colvarLockDate = new TableSchema.TableColumn(schema);
				colvarLockDate.ColumnName = "LockDate";
				colvarLockDate.DataType = DbType.DateTime;
				colvarLockDate.MaxLength = 0;
				colvarLockDate.AutoIncrement = false;
				colvarLockDate.IsNullable = false;
				colvarLockDate.IsPrimaryKey = false;
				colvarLockDate.IsForeignKey = false;
				colvarLockDate.IsReadOnly = false;
				colvarLockDate.DefaultSetting = @"";
				colvarLockDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLockDate);
				
				TableSchema.TableColumn colvarLockDateLocal = new TableSchema.TableColumn(schema);
				colvarLockDateLocal.ColumnName = "LockDateLocal";
				colvarLockDateLocal.DataType = DbType.DateTime;
				colvarLockDateLocal.MaxLength = 0;
				colvarLockDateLocal.AutoIncrement = false;
				colvarLockDateLocal.IsNullable = false;
				colvarLockDateLocal.IsPrimaryKey = false;
				colvarLockDateLocal.IsForeignKey = false;
				colvarLockDateLocal.IsReadOnly = false;
				colvarLockDateLocal.DefaultSetting = @"";
				colvarLockDateLocal.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLockDateLocal);
				
				TableSchema.TableColumn colvarLockCookie = new TableSchema.TableColumn(schema);
				colvarLockCookie.ColumnName = "LockCookie";
				colvarLockCookie.DataType = DbType.Int32;
				colvarLockCookie.MaxLength = 0;
				colvarLockCookie.AutoIncrement = false;
				colvarLockCookie.IsNullable = false;
				colvarLockCookie.IsPrimaryKey = false;
				colvarLockCookie.IsForeignKey = false;
				colvarLockCookie.IsReadOnly = false;
				colvarLockCookie.DefaultSetting = @"";
				colvarLockCookie.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLockCookie);
				
				TableSchema.TableColumn colvarTimeout = new TableSchema.TableColumn(schema);
				colvarTimeout.ColumnName = "Timeout";
				colvarTimeout.DataType = DbType.Int32;
				colvarTimeout.MaxLength = 0;
				colvarTimeout.AutoIncrement = false;
				colvarTimeout.IsNullable = false;
				colvarTimeout.IsPrimaryKey = false;
				colvarTimeout.IsForeignKey = false;
				colvarTimeout.IsReadOnly = false;
				colvarTimeout.DefaultSetting = @"";
				colvarTimeout.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTimeout);
				
				TableSchema.TableColumn colvarLocked = new TableSchema.TableColumn(schema);
				colvarLocked.ColumnName = "Locked";
				colvarLocked.DataType = DbType.Boolean;
				colvarLocked.MaxLength = 0;
				colvarLocked.AutoIncrement = false;
				colvarLocked.IsNullable = false;
				colvarLocked.IsPrimaryKey = false;
				colvarLocked.IsForeignKey = false;
				colvarLocked.IsReadOnly = false;
				colvarLocked.DefaultSetting = @"";
				colvarLocked.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLocked);
				
				TableSchema.TableColumn colvarSessionItemShort = new TableSchema.TableColumn(schema);
				colvarSessionItemShort.ColumnName = "SessionItemShort";
				colvarSessionItemShort.DataType = DbType.Binary;
				colvarSessionItemShort.MaxLength = 7000;
				colvarSessionItemShort.AutoIncrement = false;
				colvarSessionItemShort.IsNullable = true;
				colvarSessionItemShort.IsPrimaryKey = false;
				colvarSessionItemShort.IsForeignKey = false;
				colvarSessionItemShort.IsReadOnly = false;
				colvarSessionItemShort.DefaultSetting = @"";
				colvarSessionItemShort.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSessionItemShort);
				
				TableSchema.TableColumn colvarSessionItemLong = new TableSchema.TableColumn(schema);
				colvarSessionItemLong.ColumnName = "SessionItemLong";
				colvarSessionItemLong.DataType = DbType.Binary;
				colvarSessionItemLong.MaxLength = 2147483647;
				colvarSessionItemLong.AutoIncrement = false;
				colvarSessionItemLong.IsNullable = true;
				colvarSessionItemLong.IsPrimaryKey = false;
				colvarSessionItemLong.IsForeignKey = false;
				colvarSessionItemLong.IsReadOnly = false;
				colvarSessionItemLong.DefaultSetting = @"";
				colvarSessionItemLong.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSessionItemLong);
				
				TableSchema.TableColumn colvarFlags = new TableSchema.TableColumn(schema);
				colvarFlags.ColumnName = "Flags";
				colvarFlags.DataType = DbType.Int32;
				colvarFlags.MaxLength = 0;
				colvarFlags.AutoIncrement = false;
				colvarFlags.IsNullable = false;
				colvarFlags.IsPrimaryKey = false;
				colvarFlags.IsForeignKey = false;
				colvarFlags.IsReadOnly = false;
				
						colvarFlags.DefaultSetting = @"((0))";
				colvarFlags.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFlags);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["mainConnection"].AddSchema("ASPStateTempSessions",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("SessionId")]
		[Bindable(true)]
		public string SessionId 
		{
			get { return GetColumnValue<string>(Columns.SessionId); }
			set { SetColumnValue(Columns.SessionId, value); }
		}
		  
		[XmlAttribute("Created")]
		[Bindable(true)]
		public DateTime Created 
		{
			get { return GetColumnValue<DateTime>(Columns.Created); }
			set { SetColumnValue(Columns.Created, value); }
		}
		  
		[XmlAttribute("Expires")]
		[Bindable(true)]
		public DateTime Expires 
		{
			get { return GetColumnValue<DateTime>(Columns.Expires); }
			set { SetColumnValue(Columns.Expires, value); }
		}
		  
		[XmlAttribute("LockDate")]
		[Bindable(true)]
		public DateTime LockDate 
		{
			get { return GetColumnValue<DateTime>(Columns.LockDate); }
			set { SetColumnValue(Columns.LockDate, value); }
		}
		  
		[XmlAttribute("LockDateLocal")]
		[Bindable(true)]
		public DateTime LockDateLocal 
		{
			get { return GetColumnValue<DateTime>(Columns.LockDateLocal); }
			set { SetColumnValue(Columns.LockDateLocal, value); }
		}
		  
		[XmlAttribute("LockCookie")]
		[Bindable(true)]
		public int LockCookie 
		{
			get { return GetColumnValue<int>(Columns.LockCookie); }
			set { SetColumnValue(Columns.LockCookie, value); }
		}
		  
		[XmlAttribute("Timeout")]
		[Bindable(true)]
		public int Timeout 
		{
			get { return GetColumnValue<int>(Columns.Timeout); }
			set { SetColumnValue(Columns.Timeout, value); }
		}
		  
		[XmlAttribute("Locked")]
		[Bindable(true)]
		public bool Locked 
		{
			get { return GetColumnValue<bool>(Columns.Locked); }
			set { SetColumnValue(Columns.Locked, value); }
		}
		  
		[XmlAttribute("SessionItemShort")]
		[Bindable(true)]
		public byte[] SessionItemShort 
		{
			get { return GetColumnValue<byte[]>(Columns.SessionItemShort); }
			set { SetColumnValue(Columns.SessionItemShort, value); }
		}
		  
		[XmlAttribute("SessionItemLong")]
		[Bindable(true)]
		public byte[] SessionItemLong 
		{
			get { return GetColumnValue<byte[]>(Columns.SessionItemLong); }
			set { SetColumnValue(Columns.SessionItemLong, value); }
		}
		  
		[XmlAttribute("Flags")]
		[Bindable(true)]
		public int Flags 
		{
			get { return GetColumnValue<int>(Columns.Flags); }
			set { SetColumnValue(Columns.Flags, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varSessionId,DateTime varCreated,DateTime varExpires,DateTime varLockDate,DateTime varLockDateLocal,int varLockCookie,int varTimeout,bool varLocked,byte[] varSessionItemShort,byte[] varSessionItemLong,int varFlags)
		{
			ASPStateTempSession item = new ASPStateTempSession();
			
			item.SessionId = varSessionId;
			
			item.Created = varCreated;
			
			item.Expires = varExpires;
			
			item.LockDate = varLockDate;
			
			item.LockDateLocal = varLockDateLocal;
			
			item.LockCookie = varLockCookie;
			
			item.Timeout = varTimeout;
			
			item.Locked = varLocked;
			
			item.SessionItemShort = varSessionItemShort;
			
			item.SessionItemLong = varSessionItemLong;
			
			item.Flags = varFlags;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varSessionId,DateTime varCreated,DateTime varExpires,DateTime varLockDate,DateTime varLockDateLocal,int varLockCookie,int varTimeout,bool varLocked,byte[] varSessionItemShort,byte[] varSessionItemLong,int varFlags)
		{
			ASPStateTempSession item = new ASPStateTempSession();
			
				item.SessionId = varSessionId;
			
				item.Created = varCreated;
			
				item.Expires = varExpires;
			
				item.LockDate = varLockDate;
			
				item.LockDateLocal = varLockDateLocal;
			
				item.LockCookie = varLockCookie;
			
				item.Timeout = varTimeout;
			
				item.Locked = varLocked;
			
				item.SessionItemShort = varSessionItemShort;
			
				item.SessionItemLong = varSessionItemLong;
			
				item.Flags = varFlags;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn SessionIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ExpiresColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn LockDateColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn LockDateLocalColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn LockCookieColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn TimeoutColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn LockedColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn SessionItemShortColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn SessionItemLongColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn FlagsColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string SessionId = @"SessionId";
			 public static string Created = @"Created";
			 public static string Expires = @"Expires";
			 public static string LockDate = @"LockDate";
			 public static string LockDateLocal = @"LockDateLocal";
			 public static string LockCookie = @"LockCookie";
			 public static string Timeout = @"Timeout";
			 public static string Locked = @"Locked";
			 public static string SessionItemShort = @"SessionItemShort";
			 public static string SessionItemLong = @"SessionItemLong";
			 public static string Flags = @"Flags";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
